package org.hishenframework.data;

import java.util.List;

public class Page {
	/**
	 * 每页记录数量
	 */
	private int pageSize = 10;
	/**
	 * 总记录数
	 */
	private int totalCount = 0;
	/**
	 * 当前页码
	 */
	private int currentPage = 1;
	/**
	 * 结果集
	 */
	private List<Object> result;
	
	/**
	 * 获得起始记录数
	 * @return
	 */
	public int getOffset() {
		return (currentPage - 1) * pageSize;
	}

	/**
	 * 页面总数
	 */
	public int getTotalPages() {
		int totalPages = totalCount / pageSize;
		if(totalCount % pageSize > 0)
			totalPages++;
		return totalPages;
	}
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize > 0 ? pageSize : this.pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage > 0 ? currentPage : this.currentPage;
	}

	public List<Object> getResult() {
		return result;
	}

	public void setResult(List<Object> result) {
		this.result = result;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount > - 1 ? totalCount : this.totalCount;
	}

}
